<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script>
	//0-99之间的随机整数
	var ran = parseInt(Math.random() * 100);

	function guess() {
		//获取文本框中的值
		var n = document.getElementById("num").value;
		//获取span
		var span = document.getElementById("result");
		//判断该值是否为数字
		if (isNaN(n)) {
			//不是数字，给予提示
			span.innerHTML = "请输入数字";
		} else {
			//是数字，进行比较
			if (n > ran) {
				span.innerHTML = "大了";
			} else if (n < ran) {
				span.innerHTML = "小了";
			} else {
				span.innerHTML = "对了";
			}
		}
	}
</script>
</head>
<body>
	<input type="text" id="num" />
	<input type="button" value="猜" onclick="guess();" />
	<span id="result"></span>
</body>
</html>







